package com.ksyun.campus.dataserver.util;
import java.io.File;
import java.io.IOException;
import java.nio.file.FileStore;
import java.nio.file.Files;
import java.nio.file.Path;

public class DiskCapacity {
    public static void main(String[] args) {
        File[] roots = File.listRoots();

        for (File root : roots) {
            System.out.println("磁盘根目录：" + root.getAbsolutePath());

            try {
                Path path = root.toPath();
                FileStore fileStore = Files.getFileStore(path);

                long totalSpace = fileStore.getTotalSpace();
                long usableSpace = fileStore.getUsableSpace();

                System.out.println("总容量：" + totalSpace / (1024 * 1024) + " MB");
                System.out.println("可用容量：" + usableSpace / (1024 * 1024) + " MB");
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}